using System;

namespace DaaseVarmer.model
{
    public class TemperatureReadings
    {
        private const int LIST_SIZE = 20;
        private DateTempPair[] _pairs = new DateTempPair[LIST_SIZE];

        public void addEntry(String date, int temperature)
        {
            shiftEntries();
            _pairs[0] = new DateTempPair(date, temperature);
        }

        // Shifts all entries in _pairs by 1 to make room for the new entry at index 0.
        private void shiftEntries()
        {
            for (int i = LIST_SIZE - 1; i > 0; i--)
            {
                _pairs[i] = _pairs[i - 1];
            }
        }

        public DateTempPair getPairAtIndex(int i)
        {
            try
            {
                if ( _pairs[i] == null ) return new DateTempPair("No temperature recorded", -1);
                return _pairs[i];
            }
            catch (Exception e)
            {
                return new DateTempPair("No temperature recorded", -1);
            }
        }

        public  DateTempPair[] getTemperaturReadings()
        {
            DateTempPair[] dateTemp = new DateTempPair[LIST_SIZE];

            for (int i = 0; i < LIST_SIZE; i++)
            {
                _pairs.CopyTo(dateTemp, i);
            }
            return dateTemp;
        }

        public int this[int index]
        {
            get
            {
                if (_pairs[index] != null)
                {
                    return _pairs[index].getTemperature();
                }
                return -5000;
            }

        }

        private DateTempPair DateTempPair { get; set; }    
     
    }
}
